package ${package}.controller;

import ${package}.service.${model}Service;
import ${package}.dto.${model}Dto;
import ${package}.model.${model};
import ${package}.dto.RequestDto;
import ${package}.dto.ResponseDto;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;

/**
 * Created by util on ${now?date}.
 */
@Api(description = "${model?lower_case}相关api")
@RestController
@RequestMapping("/${model?lower_case}")
public class ${model}Controller {

    @Autowired
    private ${model}Service ${model?uncap_first}Service;

    @PostMapping("/select${model}List")
    @ApiOperation(value = "获取${model?uncap_first}列表")
    public ResponseDto<List<${model}>> select${model}List(@RequestBody RequestDto<${model}Dto> requestDto){
        List<${model}> ${model?uncap_first}List = ${model?uncap_first}Service.select${model}List(requestDto.getModel());
        return ResponseDto.successWithData(${model?uncap_first}List);
    }
    
    @PostMapping("/select${model}Page")
    @ApiOperation(value = "获取${model?uncap_first}分页列表")
    public ResponseDto<PageInfo<${model}>> select${model}Page(@RequestBody RequestDto<${model}Dto> requestDto){
        PageInfo pageInfo = ${model?uncap_first}Service.select${model}Page(requestDto.getModel());
        return ResponseDto.successWithData(pageInfo);
    }

    @PostMapping("/select${model}ById")
    @ApiOperation(value = "通过id获取${model?uncap_first}")
    public ResponseDto<${model}> select${model}ById(@RequestBody RequestDto<${model}Dto> requestDto){
        ${model} ${model?uncap_first} = ${model?uncap_first}Service.select${model}ById(requestDto.getModel());
        return ResponseDto.successWithData(${model?uncap_first});
    }

    @PostMapping("/insert${model}")
    @ApiOperation(value = "通过${model?uncap_first}新增")
    public ResponseDto<Boolean> insert${model}(@RequestBody RequestDto<${model}Dto> requestDto){
        boolean flag = ${model?uncap_first}Service.insert${model}(requestDto.getModel());
        return ResponseDto.successWithData(flag);
    }

    @PostMapping("/update${model}")
    @ApiOperation(value = "通过${model?uncap_first}更新")
    public ResponseDto<Boolean> update${model}(@RequestBody RequestDto<${model}Dto> requestDto){
        boolean flag = ${model?uncap_first}Service.update${model}(requestDto.getModel());
        return ResponseDto.successWithData(flag);
    }

    @PostMapping("/delete${model}")
    @ApiOperation(value = "通过${model?uncap_first}删除")
    public ResponseDto<Boolean> delete${model}(@RequestBody RequestDto<${model}Dto> requestDto){
        boolean flag = ${model?uncap_first}Service.delete${model}(requestDto.getModel());
        return ResponseDto.successWithData(flag);
    }
    
}
